home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / What's New? / Tool Chest / ColorSync™ 1.0.5 / Dummy CMM / DummyCMM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-11  |  4.9 KB  |  204 lines  |  [TEXT/KAHL]

  1. /*
  2. ** Color Matching Method (CMM) Component Shell
  3.  
  4.     93.06.26    tem        Fix version returned by ComponentVersion(…)
  5.                         Rework ComponentCanDo(…)
  6.  
  7. */
  8.  
  9. #include <QuickDraw.h>
  10. #include <Components.h>
  11. #include <CMComponent.h>
  12. #include <CMApplication.h>
  13. #include <Memory.h>
  14.  
  15. /* Prototypes of CMS component routines */
  16.  
  17. pascal CMError    ComponentOpen(Handle storage, ComponentInstance self);
  18. pascal CMError    ComponentClose(Handle storage, ComponentInstance self);
  19. pascal long     ComponentCanDo(Handle storage, short selector);
  20. pascal long     ComponentVersion(Handle storage); 
  21. pascal CMError    CMMInit( Handle storage, CMProfileHandle srcProfile, CMProfileHandle dstProfile);
  22. pascal CMError    CMMMatchColors( Handle storage, CMColorList myColors, long count );
  23. pascal CMError    CMMGamutTest( Handle storage, CMColorList myColors, long count, CMGamutResult result );
  24.  
  25.  
  26.  
  27. #define     CMCodeVersion                1
  28.  
  29. /* Build a code resource */
  30. #define realthing
  31.  
  32. #ifdef realthing
  33. pascal ComponentResult main( ComponentParameters *params, Handle storage )
  34. #else
  35. pascal ComponentResult CMM( ComponentParameters *params, Handle storage )
  36. #endif
  37. {
  38.     ComponentFunction    routineToCall = 0; 
  39.     short                message = params->what;        
  40.     CMError                result;
  41.  
  42.     if (message < 0) {
  43.         switch (message) {
  44.             case kComponentOpenSelect          : routineToCall = (ComponentFunction)ComponentOpen;
  45.                                               break; 
  46.             case kComponentCloseSelect      : routineToCall = (ComponentFunction)ComponentClose; 
  47.                                               break; 
  48.             case kComponentCanDoSelect      : routineToCall = (ComponentFunction)ComponentCanDo; 
  49.                                               break; 
  50.             case kComponentVersionSelect     : routineToCall = (ComponentFunction)ComponentVersion;
  51.             default                         : return (noErr);
  52.         }
  53.     }
  54.     else {
  55.         switch (message) {
  56.              case kCMInit                     : routineToCall = (ComponentFunction)CMMInit;        
  57.                                               break; 
  58.             case kCMMatchColors                 : routineToCall = (ComponentFunction)CMMMatchColors;    
  59.                                               break; 
  60.             case kCMGamutTest                 : routineToCall = (ComponentFunction)CMMGamutTest;    
  61.                                               break; 
  62.             default                         : return (CMUnimplementedError);
  63.         }
  64.     };
  65.     
  66.      result = CallComponentFunctionWithStorage(storage, params, routineToCall); 
  67.  
  68.      return result;
  69. }
  70.  
  71. pascal CMError ComponentOpen(Handle storage, ComponentInstance self) 
  72.     Handle myStorage; /* allocate dummy handle for private storage */ 
  73.  
  74.     myStorage = (Handle) NewHandle( sizeof( long ) ); 
  75.     SetComponentInstanceStorage( self, myStorage ); 
  76.     return( noErr ); 
  77. }
  78.  
  79. /* This is the DisposeMatchData call -- Clean up private storage */
  80. pascal CMError ComponentClose(Handle storage, ComponentInstance self) 
  81.     DisposHandle( storage );
  82.     return( noErr ); 
  83. }
  84.  
  85. pascal long ComponentCanDo(Handle storage, short selector)
  86. {
  87.     long    result;
  88.     
  89.     switch (selector)
  90.     {
  91.         /* Component Manager selectors */
  92.         case kComponentOpenSelect:
  93.         case kComponentCloseSelect:
  94.         case kComponentCanDoSelect:
  95.         case kComponentVersionSelect:
  96.             result = true;
  97.             break;
  98.         case kComponentRegisterSelect:
  99.         case kComponentTargetSelect:
  100.             result = false;
  101.             break;
  102.         
  103.         /* CMM Component selectors */
  104.         case kCMInit:
  105.         case kCMMatchColors:
  106.         case kCMGamutTest:
  107.             result = true;
  108.             break;
  109.             
  110.         case kCMMatchPixMap:
  111.         case kCMCheckPixMap:
  112.         case kCMConcatenateProfiles:
  113.             result = false;
  114.             break;
  115.         
  116.         default:
  117.             result = false;
  118.             break;
  119.     }
  120.  
  121.     return (result);
  122. }
  123.  
  124. pascal long ComponentVersion(Handle storage) 
  125. {
  126.     /* interface version in hi word, */ 
  127.     /* code rev in lo word  */ 
  128.     return(((CMInterfaceVersion << 16) | CMCodeVersion));      
  129. }
  130.  
  131. pascal CMError CMMInit( Handle storage, CMProfileHandle src, CMProfileHandle dst )
  132. {
  133.     /* Do something intelligent here, like fill out storage with conversion info */
  134.  
  135.     if( (**dst).header.size == sizeof(CMHeader) )
  136.         **storage = 0L;
  137.     else
  138.         **storage = 0xffffffffL;    /* flag matching should occur */        
  139.         
  140.     return( noErr );
  141.  
  142.  
  143. pascal CMError CMMMatchColors( Handle storage, CMColorList myColors, long count )
  144. {
  145.     long         iii;
  146.     CMError        error;
  147.     long        index;
  148.     RGBColor    *myColorPtr;    /* A real CMM would use CMColor* */
  149.  
  150.     if( **storage )    /* only match if flagged */
  151.     {
  152.         for (iii=0; iii<count; iii++)
  153.         {
  154.             myColorPtr = (RGBColor *)(((char *)myColors) + (iii<<3));
  155.             
  156.             /* Just invert the RGB components */
  157.             (*myColorPtr).red = ~(*myColorPtr).red;
  158.             (*myColorPtr).green = ~(*myColorPtr).green;
  159.             (*myColorPtr).blue = ~(*myColorPtr).blue;
  160.         }
  161.     }
  162.  
  163.     return( noErr );
  164.  
  165.  
  166. pascal CMError CMMGamutTest( Handle storage, CMColorList myColors, long count, CMGamutResult result )
  167. {
  168.     unsigned long    mask;
  169.     long            dstLong;
  170.     long             iii;
  171.     RGBColor        *myColorPtr;    /* A real CMM would use CMColor* */
  172.  
  173.     /* Fill out CMGamutResult bit-field.  */
  174.  
  175.     mask = 0x80000000;
  176.     dstLong = 0;
  177.     for (iii=0; iii<count; iii++)
  178.     {
  179.         myColorPtr = (RGBColor *)(((char *)myColors) + (iii<<3));
  180.         
  181.         if( (*myColorPtr).red >= 0x8000 )
  182.         {
  183.             dstLong |= mask;
  184.         }
  185.         mask >>= 1;
  186.         if( !mask )
  187.         {
  188.             mask = 0x80000000;
  189.             *result++ = dstLong;
  190.             dstLong = 0;
  191.         }
  192.     }
  193.     if (mask != 0x80000000)
  194.             *result = dstLong;
  195.  
  196.     return( noErr );
  197.  
  198.  
  199.